package com.shortlink.controller;

import com.shortlink.pojos.dto.dataobject.PageResult;
import com.shortlink.pojos.dto.dataobject.ResponseResult;
import com.shortlink.pojos.dto.req.RecyclePageQueryReqDTO;
import com.shortlink.pojos.dto.resp.LinkRespDTO;
import com.shortlink.service.ILinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/recycle")
@Api(tags = "回收站模块")
public class RecycleController {
    @Autowired
    ILinkService iLinkService;

    @GetMapping("/page")
    @ApiOperation("分页查询站内链接")
    public ResponseResult<PageResult<LinkRespDTO>> page(RecyclePageQueryReqDTO recyclePageQueryReqDTO){
        PageResult<LinkRespDTO> pageResult=iLinkService.pageRecycleLink(recyclePageQueryReqDTO);
        return ResponseResult.okResult(pageResult);
    }

    @DeleteMapping("/delete/{shortUri}")
    @ApiOperation("移除站内链接")
    public ResponseResult delete(@PathVariable String shortUri){
        iLinkService.deleteRecycleLink(shortUri);
        return ResponseResult.okResult();
    }

    /**
     * 恢复短链接
     * enable validDate不变
     * @param shortUri
     * @return
     */
    @PutMapping("/recover/{shortUri}")
    @ApiOperation("恢复站内链接")
    public ResponseResult recover(@PathVariable String shortUri){
        iLinkService.recoverRecycleLink(shortUri);
        return ResponseResult.okResult();
    }


}
